using System;

namespace AIFSContentManagementSystem
{
    /// <summary>
    /// This is a base class for all results sent from the service facade.
    /// </summary>
    [Serializable]
    public abstract class ResponseBase
    {
        private bool hasDataInReturn;

        public bool HasDataInReturn
        {
            get { return hasDataInReturn; }
            set { /* do nothing. This is just to expose the class to webservice*/ }
        }

        protected void SetHasDataInReturn()
        {
            hasDataInReturn = true;
        }

        public ResponseBase()
        {
            errorMessage = new System.Collections.Generic.List<string>();
            hasDataInReturn = false;
            hasError = false;
        }

        private bool hasError;
        public bool HasError
        {
            get { return hasError; }
            set { hasError = value; }
        }

        private System.Collections.Generic.List<string> errorMessage;

        /// <summary>
        /// Used to Get error message for serialization. Do not use this to Set message.
        /// Use AddErrorMessage instead.
        /// </summary>
        public System.Collections.Generic.List<string> ErrorMessage
        {
            get { return errorMessage; }
            set { ; }
        }

        internal void AddErrorMessage(string error)
        {
            if (error != null && error != string.Empty)
            {
                HasError = true;
                errorMessage.Add(error);
            }
        }

        internal void AddErrorMessage(string format, params object[] args)
        {
            if (args != null && args.Length > 0)
            {
                HasError = true;
                errorMessage.Add(string.Format(format, args));
            }
        }

        /// <summary>
        /// Method allows to copy error messages from another result
        /// </summary>
        /// <param name="result">Result from which to copy the error messages.</param>
        internal void CopyErrorMessageFrom(ResponseBase result)
        {
            if (!result.HasError)
                return;

            foreach (string message in result.ErrorMessage)
            {
                this.AddErrorMessage(message);
            }
        }        
    }
}
